home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / cdrtools-1.10 / lib / serrmsg.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-08-03  |  2.7 KB  |  117 lines

  1. /* @(#)serrmsg.c    1.1 00/08/03 Copyright 1985,2000 J. Schilling */
  2. /*
  3.  *    Routines for printing command errors
  4.  *
  5.  *    Copyright (c) 1985,2000 J. Schilling
  6.  */
  7. /*
  8.  * This program is free software; you can redistribute it and/or modify
  9.  * it under the terms of the GNU General Public License as published by
  10.  * the Free Software Foundation; either version 2, or (at your option)
  11.  * any later version.
  12.  *
  13.  * This program is distributed in the hope that it will be useful,
  14.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.  * GNU General Public License for more details.
  17.  *
  18.  * You should have received a copy of the GNU General Public License
  19.  * along with this program; see the file COPYING.  If not, write to
  20.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  */
  22.  
  23. #include <mconfig.h>
  24. #include <stdio.h>
  25. #include <standard.h>
  26. #include <stdxlib.h>
  27. #include <vadefs.h>
  28. #include <strdefs.h>
  29. #include <schily.h>
  30. #ifndef    HAVE_STRERROR
  31. extern    char    *sys_errlist[];
  32. extern    int    sys_nerr;
  33. #endif
  34.  
  35. EXPORT    int    serrmsg        __PR((char *buf, size_t maxcnt, const char *, ...));
  36. EXPORT    int    serrmsgno    __PR((int, char *buf, size_t maxcnt, const char *, ...));
  37. LOCAL    int    _serrmsg    __PR((int, char *buf, size_t maxcnt, const char *, va_list));
  38.  
  39. /* VARARGS1 */
  40. EXPORT int
  41. #ifdef    PROTOTYPES
  42. serrmsg(char *buf, size_t maxcnt, const char *msg, ...)
  43. #else
  44. serrmsg(buf, maxcnt, msg, va_alist)
  45.     char    *buf;
  46.     size_t    maxcnt;
  47.     char    *msg;
  48.     va_dcl
  49. #endif
  50. {
  51.     va_list    args;
  52.     int    ret;
  53.  
  54. #ifdef    PROTOTYPES
  55.     va_start(args, msg);
  56. #else
  57.     va_start(args);
  58. #endif
  59.     ret = _serrmsg(geterrno(), buf, maxcnt, msg, args);
  60.     va_end(args);
  61.     return (ret);
  62. }
  63.  
  64. /* VARARGS2 */
  65. #ifdef    PROTOTYPES
  66. EXPORT int
  67. serrmsgno(int err, char *buf, size_t maxcnt, const char *msg, ...)
  68. #else
  69. serrmsgno(err, buf, maxcnt, msg, va_alist)
  70.     int    err;
  71.     char    *buf;
  72.     size_t    maxcnt;
  73.     char    *msg;
  74.     va_dcl
  75. #endif
  76. {
  77.     va_list    args;
  78.     int    ret;
  79.  
  80. #ifdef    PROTOTYPES
  81.     va_start(args, msg);
  82. #else
  83.     va_start(args);
  84. #endif
  85.     ret = _serrmsg(err, buf, maxcnt, msg, args);
  86.     va_end(args);
  87.     return (ret);
  88. }
  89.  
  90. LOCAL int
  91. _serrmsg(err, buf, maxcnt, msg, args)
  92.     int        err;
  93.     char        *buf;
  94.     size_t        maxcnt;
  95.     const char    *msg;
  96.     va_list        args;
  97. {
  98.     int    ret;
  99.     char    errbuf[20];
  100.     char    *errnam;
  101.     char    *prognam = get_progname();
  102.     
  103.     if (err < 0) {
  104.         ret = js_snprintf(buf, maxcnt, "%s: %r", prognam, msg, args);
  105.     } else {
  106.         errnam = errmsgstr(err);
  107.         if (errnam == NULL) {
  108.             (void)js_snprintf(errbuf, sizeof (errbuf),
  109.                         "Error %d", err);
  110.             errnam = errbuf;
  111.         }
  112.         ret = js_snprintf(buf, maxcnt,
  113.                 "%s: %s. %r", prognam, errnam, msg, args);
  114.     }
  115.     return (ret);
  116. }
  117.